/*
 * MovimentoCaixa.java
 *
 * Created on 11/03/2009, 16:32:28
 * Copyright Jaime Junior
 */
package Adecot.Financeiro;

import com.icesoft.faces.component.ext.HtmlCommandButton;
import com.icesoft.faces.component.ext.HtmlInputText;
import com.icesoft.faces.component.jsfcl.data.PopupBean;
import com.icesoft.faces.component.jsfcl.data.SelectInputDateBean;
import com.icesoft.faces.component.panelpopup.PanelPopup;
import com.icesoft.faces.component.selectinputdate.SelectInputDate;
import com.sun.rave.web.ui.appbase.AbstractPageBean;
import javax.faces.FacesException;
import Adecot.ApplicationBean1;
import Adecot.SessionBean1;
import Adecot.RequestBean1;
import java.util.Date;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.CharacterConverter;
import javax.faces.event.ValueChangeEvent;
import javax.faces.validator.ValidatorException;


/**
 * <p>Page bean that corresponds to a similarly named JSP page.  This
 * class contains component definitions (and initialization code) for
 * all components that you have defined on this page, as well as
 * lifecycle methods and event handlers where you may add behavior
 * to respond to incoming events.</p>
 */
public class MovimentoCaixa extends AbstractPageBean {
    // <editor-fold defaultstate="collapsed" desc="Managed Component Definition">
    private int __placeholder;

    /**
     * <p>Automatically managed component initialization.  <strong>WARNING:</strong>
     * This method is automatically generated, so any user-specified code inserted
     * here is subject to being replaced.</p>
     */
    private void _init() throws Exception {
    }
    private SelectInputDateBean dataInicioSelecionada = new SelectInputDateBean();

    public SelectInputDateBean getDataInicioSelecionada() {
        return dataInicioSelecionada;
    }

    public void setDataInicioSelecionada(SelectInputDateBean sidb) {
        this.dataInicioSelecionada = sidb;
    }
    private SelectInputDate campoDataInicio = new SelectInputDate();

    public SelectInputDate getCampoDataInicio() {
        return campoDataInicio;
    }

    public void setCampoDataInicio(SelectInputDate sid) {
        this.campoDataInicio = sid;
    }
    private SelectInputDateBean dataFimSelecionada = new SelectInputDateBean();

    public SelectInputDateBean getDataFimSelecionada() {
        return dataFimSelecionada;
    }

    public void setDataFimSelecionada(SelectInputDateBean sidb) {
        this.dataFimSelecionada = sidb;
    }
    private SelectInputDate campoDataFim = new SelectInputDate();

    public SelectInputDate getCampoDataFim() {
        return campoDataFim;
    }

    public void setCampoDataFim(SelectInputDate sid) {
        this.campoDataFim = sid;
    }
    private PopupBean painelPopupSair = new PopupBean();

    public PopupBean getPainelPopupSair() {
        return painelPopupSair;
    }

    public void setPainelPopupSair(PopupBean pb) {
        this.painelPopupSair = pb;
    }
    private HtmlCommandButton botaoSairSim = new HtmlCommandButton();

    public HtmlCommandButton getBotaoSairSim() {
        return botaoSairSim;
    }

    public void setBotaoSairSim(HtmlCommandButton hcb) {
        this.botaoSairSim = hcb;
    }
    private HtmlCommandButton botaoSairNao = new HtmlCommandButton();

    public HtmlCommandButton getBotaoSairNao() {
        return botaoSairNao;
    }

    public void setBotaoSairNao(HtmlCommandButton hcb) {
        this.botaoSairNao = hcb;
    }
    private PanelPopup painelSair = new PanelPopup();

    public PanelPopup getPainelSair() {
        return painelSair;
    }

    public void setPainelSair(PanelPopup pp) {
        this.painelSair = pp;
    }
    private PopupBean panelPopup1Bean = new PopupBean();

    public PopupBean getPanelPopup1Bean() {
        return panelPopup1Bean;
    }

    public void setPanelPopup1Bean(PopupBean pb) {
        this.panelPopup1Bean = pb;
    }
    private HtmlCommandButton botaoConsultaOk = new HtmlCommandButton();

    public HtmlCommandButton getBotaoConsultaOk() {
        return botaoConsultaOk;
    }

    public void setBotaoConsultaOk(HtmlCommandButton hcb) {
        this.botaoConsultaOk = hcb;
    }
    private HtmlCommandButton botaoConsultaCancelar = new HtmlCommandButton();

    public HtmlCommandButton getBotaoConsultaCancelar() {
        return botaoConsultaCancelar;
    }

    public void setBotaoConsultaCancelar(HtmlCommandButton hcb) {
        this.botaoConsultaCancelar = hcb;
    }
    private PanelPopup painelConsulta = new PanelPopup();

    public PanelPopup getPainelConsulta() {
        return painelConsulta;
    }

    public void setPainelConsulta(PanelPopup pp) {
        this.painelConsulta = pp;
    }
    private PopupBean panelPopup1Bean1 = new PopupBean();

    public PopupBean getPanelPopup1Bean1() {
        return panelPopup1Bean1;
    }

    public void setPanelPopup1Bean1(PopupBean pb) {
        this.panelPopup1Bean1 = pb;
    }
    private PanelPopup painelAviso = new PanelPopup();

    public PanelPopup getPainelAviso() {
        return painelAviso;
    }

    public void setPainelAviso(PanelPopup pp) {
        this.painelAviso = pp;
    }
    private HtmlCommandButton botaoAvisoSim = new HtmlCommandButton();

    public HtmlCommandButton getBotaoAvisoSim() {
        return botaoAvisoSim;
    }

    public void setBotaoAvisoSim(HtmlCommandButton hcb) {
        this.botaoAvisoSim = hcb;
    }
    private HtmlCommandButton botaoNaoAviso = new HtmlCommandButton();

    public HtmlCommandButton getBotaoNaoAviso() {
        return botaoNaoAviso;
    }

    public void setBotaoNaoAviso(HtmlCommandButton hcb) {
        this.botaoNaoAviso = hcb;
    }
    private PopupBean panelPopup1Bean2 = new PopupBean();

    public PopupBean getPanelPopup1Bean2() {
        return panelPopup1Bean2;
    }

    public void setPanelPopup1Bean2(PopupBean pb) {
        this.panelPopup1Bean2 = pb;
    }
    private PanelPopup painelMensagem = new PanelPopup();

    public PanelPopup getPainelMensagem() {
        return painelMensagem;
    }

    public void setPainelMensagem(PanelPopup pp) {
        this.painelMensagem = pp;
    }
    private HtmlCommandButton botaoMensagemOk = new HtmlCommandButton();

    public HtmlCommandButton getBotaoMensagemOk() {
        return botaoMensagemOk;
    }

    public void setBotaoMensagemOk(HtmlCommandButton hcb) {
        this.botaoMensagemOk = hcb;
    }
    private CharacterConverter characterConverter1 = new CharacterConverter();

    public CharacterConverter getCharacterConverter1() {
        return characterConverter1;
    }

    public void setCharacterConverter1(CharacterConverter cc) {
        this.characterConverter1 = cc;
    }
    private CharacterConverter characterConverter2 = new CharacterConverter();

    public CharacterConverter getCharacterConverter2() {
        return characterConverter2;
    }

    public void setCharacterConverter2(CharacterConverter cc) {
        this.characterConverter2 = cc;
    }

    // </editor-fold>

    /**
     * <p>Construct a new Page bean instance.</p>
     */
    public MovimentoCaixa() {
    }

    /**
     * <p>Callback method that is called whenever a page is navigated to,
     * either directly via a URL, or indirectly via page navigation.
     * Customize this method to acquire resources that will be needed
     * for event handlers and lifecycle methods, whether or not this
     * page is performing post back processing.</p>
     * 
     * <p>Note that, if the current request is a postback, the property
     * values of the components do <strong>not</strong> represent any
     * values submitted with this request.  Instead, they represent the
     * property values that were saved for this view when it was rendered.</p>
     */
    @Override
    public void init() {
        // Perform initializations inherited from our superclass
        super.init();
        // Perform application initialization that must complete
        // *before* managed components are initialized
        // TODO - add your own initialiation code here
            
        // <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
        // Initialize automatically managed components
        // *Note* - this logic should NOT be modified
        try {
            _init();
        } catch (Exception e) {
            log("MovimentoCaixa Initialization Failure", e);
            throw e instanceof FacesException ? (FacesException) e: new FacesException(e);
        }
        painelSair.setRendered(false);
        painelConsulta.setRendered(false);
        painelAviso.setRendered(false);
        painelMensagem.setRendered(false);
        // </editor-fold>
        // Perform application initialization that must complete
        // *after* managed components are initialized
        // TODO - add your own initialization code here
    }

    /**
     * <p>Callback method that is called after the component tree has been
     * restored, but before any event processing takes place.  This method
     * will <strong>only</strong> be called on a postback request that
     * is processing a form submit.  Customize this method to allocate
     * resources that will be required in your event handlers.</p>
     */
    @Override
    public void preprocess() {
    }

    /**
     * <p>Callback method that is called just before rendering takes place.
     * This method will <strong>only</strong> be called for the page that
     * will actually be rendered (and not, for example, on a page that
     * handled a postback and then navigated to a different page).  Customize
     * this method to allocate resources that will be required for rendering
     * this page.</p>
     */
    @Override
    public void prerender() {
    }

    /**
     * <p>Callback method that is called after rendering is completed for
     * this request, if <code>init()</code> was called (regardless of whether
     * or not this was the page that was actually rendered).  Customize this
     * method to release resources acquired in the <code>init()</code>,
     * <code>preprocess()</code>, or <code>prerender()</code> methods (or
     * acquired during execution of an event handler).</p>
     */
    @Override
    public void destroy() {
    }

    /**
     * <p>Retornar uma referência para o Bean de dados limitados.</p>
     *
     * @retorna uma referência para o bean de dados limitados
     */
    protected ApplicationBean1 getApplicationBean1() {
        return (ApplicationBean1) getBean("ApplicationBean1");
    }

    /**
     * <p>Retornar uma referência para o Bean de dados limitados.</p>
     *
     * @retorna uma referência para o bean de dados limitados
     */
    protected SessionBean1 getSessionBean1() {
        return (SessionBean1) getBean("SessionBean1");
    }

    /**
     * <p>Retornar uma referência para o Bean de dados limitados.</p>
     *
     * @retorna uma referência para o bean de dados limitados
     */
    protected RequestBean1 getRequestBean1() {
        return (RequestBean1) getBean("RequestBean1");
    }

    public String botaoSairSim_action() {
        //return null means stay on the same page
        return "menu";
    }

    public String botaoSairNao_action() {
        painelSair.setRendered(false);
        return null;
    }

    public String botaoSair_action() {
        painelSair.setRendered(true);
        return null;
    }

    public String botaoConsultaOk_action() {
        painelAviso.setRendered(true);
        return null;
    }

    public String botaoConsultaCancelar_action() {
        painelConsulta.setRendered(false);
        return null;
    }

    public String botaoAvisoSim_action() {
        painelAviso.setRendered(false);
        return null;
    }

    public String botaoNaoAviso_action() {
        painelAviso.setRendered(false);
        painelConsulta.setRendered(false);
        return null;
    }

    public String botaoConsultar_action() {
        painelConsulta.setRendered(true);
        return null;
    }

   public void campoDataInicio_processValueChange(ValueChangeEvent vce) {
      
   }

    public void campoDataFim_validate(FacesContext context, UIComponent component, Object value) {

        FacesMessage msg = new FacesMessage();
        try {
            Date data = (Date) value;
            if (data.before((Date) campoDataInicio.getValue())) {
                msg.setSummary("*");
                msg.setDetail("Data entrega posterior a data do pedido");
                throw new ValidatorException(msg);
            }
        } catch (Exception e) {
            throw new ValidatorException(msg);
        }
    }
    

}

